import { baseUrlApi, requestClient, type Result } from '#/api/request';

/** 导航菜单列表 */
export const getNavMenus = (params?: { nav_id: number }) => {
  return requestClient.get<Result>(baseUrlApi('/admin/nav/menus'), {
    params,
  });
};

/** 添加导航菜单 */
export const postNavMenus = (data: any) => {
  if (data?.href) {
    delete data.external_href;
  }
  return requestClient.post<Result>(baseUrlApi('/admin/nav/menus'), data);
};

/** 获取导航菜单信息 */
export const getNavMenuInfo = (id: number) => {
  return requestClient.get<Result>(baseUrlApi(`/admin/nav/menus/${id}`));
};

/** 编辑导航菜单 */
export const putNavMenu = (id: number, data?: any) => {
  if (data.href) {
    delete data.external_href;
  }
  return requestClient.put<Result>(baseUrlApi(`/admin/nav/menus/${id}`), data);
};

/** 删除导航菜单 */
export const deleteNavMenu = (id: number) => {
  return requestClient.delete<Result>(baseUrlApi(`/admin/nav/menus/${id}`));
};

/** 切换导航菜单显示状态 */
export const postNavMenusToggle = (id: number) => {
  return requestClient.post<Result>(
    baseUrlApi(`/admin/nav/menus/${id}/toggle`),
  );
};

/** 设置导航菜单显示状态 */
export const postNavMenusStatus = (id: number, status: number) => {
  return requestClient.post<Result>(
    baseUrlApi(`/admin/nav/menus/${id}/status/${status}`),
  );
};

/** 导航菜单排序 */
export const postNavMenusListOrder = (data?: { list_orders: object }) => {
  return requestClient.post<Result>(
    baseUrlApi('/admin/nav/menus/list/order'),
    data,
  );
};
